<?php
class FindBiji{
	private $label_tandan;
	private $subbagian;
	private $db;
	
	function FindBiji($db=NULL, $subbagian=NULL, $label_tandan=NULL){
		$this->subbagian 		= $subbagian;
		$this->label_tandan = $label_tandan;
		$this->db 		 	= $db;
	}
	
	private function findPencacahan(){
		$q = "SELECT * FROM `caramel_operational`.`inv_pencacahan` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);	
		
		
		echo json_encode($r[0]);;
	}
	
	private function findDepericarpingDanPolishing(){
		$q = "SELECT * FROM `caramel_operational`.`inv_depericarping_dan_polishing` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findPencucian(){
		$q = "SELECT * FROM `caramel_operational`.`inv_pencucian` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findPengeringan(){
		$q = "SELECT * FROM `caramel_operational`.`inv_pengeringan` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findSeleksi(){
		$q = "SELECT * FROM `caramel_operational`.`inv_seleksi` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findRuangPanas(){
		$q = "SELECT * FROM `caramel_operational`.`inv_ruang_panas` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findRuangDingin(){
		$q = "SELECT * FROM `caramel_operational`.`inv_ruang_dingin` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findGerminasi(){ // either from perendaman, or ruang panas
		$q = "SELECT * FROM `caramel_operational`.`inv_germinasi` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	private function findSeleksiAkhir(){ // either from perendaman, or ruang panas
		$q = "SELECT * FROM `caramel_operational`.`inv_seleksi_akhir` WHERE `label_tandan` LIKE '".$this->label_tandan."'";
		$r = $this->db->get_results($q);		
		
		echo json_encode($r[0]);;
	}
	
	function response(){
		switch($this->subbagian){
			case 'inv_pencacahan':
				$this->findPencacahan();
				break;
			case 'inv_depericarping_dan_polishing':
				$this->findDepericarpingDanPolishing();
				break;
			case 'inv_pencucian':
				$this->findPencucian();
				break;
			case 'inv_pengeringan':
				$this->findPengeringan();
				break;
			case 'inv_seleksi':
				$this->findSeleksi();
				break;
			case 'inv_ruang_panas':
				$this->findRuangPanas();
				break;
			case 'inv_ruang_dingin':
				$this->findRuangDingin();
				break;
			case 'inv_perendaman':
				$this->findPerendaman(); // special, wae...
				break;
			case 'inv_germinasi':
				$this->findGerminasi();
				break;	
			case 'inv_seleksi_akhir':
				$this->findSeleksiAkhir();
				break;			
		}
	}	
}

$subbagian 		= $_GET['subbagian'];
$label_tandan	= $_GET['label_tandan'];


// load database class handler
include_once '../config/db_config.php';
include '../library/ezsql/shared/ez_sql_core.php';
include '../library/ezsql/mysql/ez_sql_mysql.php';

// database handler
$db = new ezSQL_mysql($dbUser, $dbPass, $dbName, $dbHost);


$finder = new FindBiji($db, $subbagian, $label_tandan);
$finder->response();
?>